<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Admin extends MY_Controller {

    /**
     * Index Page for this controller.
     *
     * Maps to the following URL
     *      http://example.com/index.php/welcome
     *  - or -  
     *      http://example.com/index.php/welcome/index
     *  - or -
     * Since this controller is set as the default controller in 
     * config/routes.php, it's displayed at http://example.com/
     *
     * So any other public methods not prefixed with an underscore will
     * map to /index.php/welcome/<method_name>
     * @see http://codeigniter.com/user_guide/general/urls.html
     */
    public function __construct() {
        parent::__construct();
        $this->load->model('general_model');
    }

    public function index() {

        parent::core_admin_view('doctor/body_view');
    }

    public function list_doctors() {
        /*         * pagination */
        $this->per_page = 20;
        $row = $this->general_model->get('doctors', '', '', '', '', 'count', 'status != "10"');
        $url = base_url() . 'admin/list_doctors/';
        parent::pagination($page, $url, $row, $this->per_page, 3);
        /*         * pagination */
        $list = $this->general_model->get('doctors', $this->start_no, $this->per_page, 'doc_id', $group_by = false, '', 'status !="10" ');
        foreach ($list as $key => $value) {
            $data['list'][] = array(
                'id' => $value['doc_id'],
                'name' => $value['doc_name'] . "  " . $value['doc_lname'],
                'type' => "doctor",
            );
        }
        $view = 'core_' . $this->usertype . '_view';
        parent::core_admin_view('doctor/list_user');
    }

    public function list_staff() {

        /*         * pagination */
        $this->per_page = 20;
        $row = $this->general_model->get('staffs', '', '', '', '', 'count', 'status != "10"');
        $url = base_url() . 'admin/list_staff/';
        parent::pagination($page, $url, $row, $this->per_page, 3);
        /*         * pagination */
        $list = $this->general_model->get('staffs', $this->start_no, $this->per_page, 'sf_id', $group_by = false, '', 'status !="10" ');
        foreach ($list as $key => $value) {
            $data['list'][] = array(
                'id' => $value['sf_id'],
                'name' => $value['sf_name'] . "  " . $value['sf_lname'],
                'type' => "staff",
            );
        }

        parent::core_admin_view('doctor/list_user');
    }

    public function list_tech() {
        /*         * pagination */
        $this->per_page = 20;
        $row = $this->general_model->get('techs', '', '', '', '', 'count', 'status != "10"');
        $url = base_url() . 'admin/list_tech/';
        parent::pagination($page, $url, $row, $this->per_page, 3);
        /*         * pagination */
        $data['list'] = $this->general_model->get('techs', $this->start_no, $this->per_page, 'tech_id', $group_by = false, '', 'status !="10" ');
        foreach ($list as $key => $value) {
            $data['list'][] = array(
                'id' => $value['sf_id'],
                'name' => $value['tech_name'] . "  " . $value['tech_lname'],
                'type' => "tech",
            );
        }

        parent::core_admin_view('doctor/list_user');
    }

    public function del_redel($id, $type_user, $val) {
        $data = array('status' => $val);

        if ($type_user == 'doctor') {
            $this->db->where('doc_id', $id);
            $this->db->update('doctors', $data);
        } elseif ($type_user == 'staff') {
            $this->db->where('sf_id', $id);
            $this->db->update('staffs', $data);
        } elseif ($type_user == 'tech') {
            $this->db->where('tech_id', $id);
            $this->db->update('techs', $data);
        }

        $ref = $this->input->server('HTTP_REFERER', TRUE);
        redirect($ref, 'location')
    }

}
